package com.yy.ant.chat.service.impl;

import com.yy.ant.chat.entity.Message;
import com.yy.ant.chat.mapper.MessageMapper;
import com.yy.ant.chat.service.IMessageService;
import com.yy.ant.sys.entity.User;
import com.yy.ant.sys.mapper.UserMapper;
import com.yy.model.ResultMsg;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 加群消息 服务实现类
 * </p>
 *
 * @author liyingying
 * @since 2020-01-06
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService {

	@Autowired
	private MessageMapper messageMapper;
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public List<Message> unreadMsgCount(String id) {
		List<Message> list=messageMapper.selectList(new QueryWrapper<Message>().eq("uid", id).eq("read", 0).orderByDesc("time"));
		for(Message o:list){
			if (o.getFrom()!=null) {
				Long from_id = o.getFrom();
				User u = userMapper.selectById(from_id);
				o.setUser(u);
			}
		}
		return list;
	}

}
